<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(function() {
		var expressTree = JSON.parse('${expressTree}');
		$('#form input[name="residenceId"]').val('${residenceId}');
		
		$('#expressIds').tree({
			data : expressTree,
			parentField : 'pid',
			checkbox:true,
			lines : true,
			check:true,
			onLoadSuccess : function() {
				parent.$.messager.progress('close');				
			}
		});
		
		$('#form').form({
			url : '/residenceController/saveResidenceExpress',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				var nodes = $('#expressIds').tree('getChecked');
				if(nodes){
					var nodestrs = '';
					for(var key in nodes){
						if(nodestrs != ''){
							nodestrs += ',';
						} 
						if(nodes[key].id != 0) {
							nodestrs += nodes[key].id;
						}
					}
					
					$('#form input[name="expressIds"]').val(nodestrs);
				}
				
				if (!isValid) {
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				try{
					parent.$.messager.progress('close');
					result = $.parseJSON(result);
					if (result.success) {
						parent.$.modalDialog.openner_dataGrid.datagrid('reload');
						parent.$.modalDialog.handler.dialog('close');
					} else{
						parent.$.messager.alert("提示",result.msg, 'info');
					}
					
				} catch(e){
					parent.$.messager.alert("提示",result, 'info');
				}
			}
		});
	});
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;width: 100%;height: 100%">
		<form id="form" method="post" style="width: 100%;height: 100%">
			<table class="table table-hover table-condensed"  style="width: 100%;height: 100%">
				<tr style="height: 200px">
					<th>关联快递公司</th>
					<td style="overflow: auto;">
					<div id="expressIds" style="height: 100%;width: 100%;overflow: auto;" ></div>
					
					<input type="hidden" name="expressIds"/>
					<input type="hidden" name="residenceId"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>